#include "MsgHandler.h"
#include "Globals.h"
#include <stdio.h>
#include "aoi/PacketID.h"

void Dispatch(Msg* pMsg)
{
    switch(pMsg->GetID()){
        case CG_MOVE:
            OnCGMove(pMsg);
            break;
        case CG_STOP_MOVE:
            OnCGStopMove(pMsg);
            break;
        default:
            fprintf(stderr, "Invalid packet id:%d\n", pMsg->GetID());
    }
}

void OnCGMove(Msg* pMsg)
{
    Obj * pObj = g_pFD2Obj->Get(pMsg->GetObjFD());
    if (!pObj){
        fprintf(stderr, "null obj\n");
        return;
    }

    if (!pObj->GetScene()){

        fprintf(stderr, "null scene, obj not ready, status:%d, type:%d\n", pObj->GetStatus(), pObj->GetType());
        return;
    }

    pObj->OnCGMove(pMsg);         
}

void OnCGStopMove(Msg* pMsg)
{
    Obj * pObj = g_pFD2Obj->Get(pMsg->GetObjFD());
    if (!pObj){
        fprintf(stderr, "null obj\n");
        return;
    }

    if (!pObj->GetScene()){
        fprintf(stderr, "null scene, obj not ready, status:%d, type:%d\n", pObj->GetStatus(), pObj->GetType());
        return;
    }

    pObj->OnCGStopMove(pMsg);  
}
